package course.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.ListSelectionModel;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import course.controller.CourseControllerListener;
import course.po.Course;

public class CourseFrame extends JFrame {
	private static final long serialVersionUID = 833796815648347358L;
	private CourseControllerListener controllerListener;
	private static JScrollPane tablePanel;
	public static int isbn = -1;

	public CourseFrame() {
		this.controllerListener = new CourseControllerListener();
		this.controllerListener.setCourseFrame(this);
		this.setJMenuBar(getCourseMenuBar());
		this.add(new CourseJPanel());
		//this.add(this.getCourseTablePanel(controllerListener.getCourseService().findAllCourse()),BorderLayout.CENTER);
		this.setSize(1090, 810);
		this.setResizable(false);
		this.setVisible(true);
		this.setLocationRelativeTo(null);
		this.validate();
	}

	private JToolBar getCourseModifyToolBar() {
		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);
		toolBar.setBorder(new BevelBorder(BevelBorder.RAISED));
		toolBar.setAlignmentX(LEFT_ALIGNMENT);
		JButton addCourseButtton = new JButton("添加");
		JButton searchCourseButtton = new JButton("查询");
		JButton updateCourseButtton = new JButton("修改");
		JButton deleteCourseButtton = new JButton("删除");
		addCourseButtton.addActionListener(controllerListener);
		searchCourseButtton.addActionListener(controllerListener);
		updateCourseButtton.addActionListener(controllerListener);
		deleteCourseButtton.addActionListener(controllerListener);
		addCourseButtton.setActionCommand("addCourseDialog");
		searchCourseButtton.setActionCommand("searchCourseDialog");
		updateCourseButtton.setActionCommand("updateCourseDialog");
		deleteCourseButtton.setActionCommand("deleteCourseDialog");
		toolBar.add(addCourseButtton);
		toolBar.add(new JToolBar.Separator());
		toolBar.add(searchCourseButtton);
		toolBar.add(new JToolBar.Separator());
		toolBar.add(updateCourseButtton);
		toolBar.add(new JToolBar.Separator());
		toolBar.add(deleteCourseButtton);
		return toolBar;
	}

	

	private JMenuBar getCourseMenuBar() {
		JMenuItem listCourseMenuItem = new JMenuItem("课程列表");
		   ImageIcon listCourseMenuItemIcon = new ImageIcon(CourseFrame.class.getResource("/courses.png"));
		   listCourseMenuItem.setIcon(listCourseMenuItemIcon);
		listCourseMenuItem.addActionListener(controllerListener);
		listCourseMenuItem.setActionCommand("refreshCourseFrame");
		JMenuBar bar = new JMenuBar();
		JMenu fileMenu = new JMenu("课程管理");
		fileMenu.add(listCourseMenuItem);
		bar.add(fileMenu);
		return bar;
	}

	public CourseControllerListener getControllerListener() {
		return controllerListener;
	}

	public int getIsbn() {
		return isbn;
	}

}
